home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: kanze@gabi-soft.fr (J. Kanze)
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 11 Apr 1996 12:04:54 -0500
- Organization: GABI Software, Sarl.
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4kje3m$9ut@solutions.solon.com>
- References: <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com>
- <4jv6st$crf@solutions.solon.com> <4k1qh3$5hn@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4kg8hu$ij7@solutions.solon.com>
- schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) writes:
-
- |> |> What is obfuscation is using pointers when the original data is an array
- |> |> (or vice-versa).
-
- |> In which situations would you use pointer arithmetic?
-
- Explicitly, with the exception of ++ and -- (and maybe += and -=),
- fairly rarely. (Implicitly, of course, everytime I write a[ i ]:-).)
- In general, when I use pointer arithmetic at all (including ++), it is
- because I am viewing the memory as some sort of a sequential file, with
- *p as a non-destructive peek operation, and *p ++ as a read. In such
- cases, I would used *(p + 1) (rather than p[ 1 ]) to do look-ahead. Off
- hand, the only instance of this that I can recall is in parsing
- character sets in regular expressions ([...]). I have a bit of code
- that is basically:
-
- while ( *p != ']' && *p != '\0' )
- {
- if ( *(p + 1) == '-' && *(p + 2) != ']' )
- {
- /* Process a range */
- p += 3 ;
- }
- else
- {
- /* Process a single character */
- p ++ ;
- }
- }
-
- I think that the key point is consistency in a given context. If I'm
- calculating some complex integral value to use as an index, I'm not
- suddenly going to switch to pointer arithmetic. In the above case, I am
- scanning a string, using p++ to advance. So, IMHO, suddenly shifting to
- array notation locally would be confusing.
- --
- James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
- GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
- Conseils en informatique industrielle --
- -- Beratung in industrieller Datenverarbeitung
-